program Summators;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  Summator = class
    res, n: Integer;
    procedure Sum; virtual;
  end;
  SmartSummator = class (Summator)
    procedure Sum; override;
  end;

var
  s: Summator;

{ Summator }

procedure Summator.Sum;
var
  i: Integer;
begin
  for i:=0 to n-1 do
  begin
    res:=res+i+1;
  end;
  Writeln ('The sum is ', res);
end;

{ SmartSummator }

procedure SmartSummator.Sum;
begin
  res:=n*(n+1) div 2;
  Writeln ('The sum is ', res);
end;

begin
  s:= Summator.Create;
  s.n:=27;
  s.Sum;
  s:= SmartSummator.Create;
  s.n:=27;
  s.Sum;
  Readln;
end.
